using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace MobileEditor
{
	public class BufferSettings
	{
		public EventHandler FilenameChanged;
		public EventHandler TitleChanged;


		private Encoding _encoding;
		private string _filename;
		private string _title;


		public BufferSettings(string title)
		{
			Title = title;
		}

		public BufferSettings(string title, string filename)
			: this(title)
		{
			Filename = filename;
		}


		public Encoding Encoding
		{
			get { return _encoding; }
			set { _encoding = value; }
		}

		public string Filename
		{
			get { return _filename; }
			set
			{
				if (_filename != value)
				{
					_filename = value;
					OnFilenameChanged(new EventArgs());
				}
			}
		}

		public string Title
		{
			get { return (_title.Length == 0 ? Path.GetFileName(Filename) : _title); }
			set
			{
				if (_title != value)
				{
					_title = value;
					OnTitleChanged(new EventArgs());
				}
			}
		}


		virtual protected void OnFilenameChanged(EventArgs e)
		{
			if (FilenameChanged != null) FilenameChanged(this, e);
		}

		virtual protected void OnTitleChanged(EventArgs e)
		{
			if (TitleChanged != null) TitleChanged(this, e);
		}

		public override string ToString()
		{
			return Title;
		}
	}
}
